package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wmmedia.dtos.WmMaterialDTO;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
@Api(value = "自媒体图文素材信息API", tags = "自媒体图文素材信息API")
public class WmMaterialController {
    @Autowired
    private WmMaterialService wmMaterialService;

    //图片上传
    @PostMapping("/upload_picture")
    @ApiOperation("图片上传")
    public ResponseResult uploadPicture(MultipartFile multipartFile){
        return wmMaterialService.uploadPicture(multipartFile);
    }

    //素材列表加载
    @PostMapping("/list")
    @ApiOperation("素材列表加载")
    public ResponseResult findList(@RequestBody WmMaterialDTO dto){
        return wmMaterialService.findList(dto);
    }

    //图片删除
    @GetMapping("/del_picture/{id}")
    @ApiOperation("图片删除")
    public ResponseResult deletePic(@PathVariable("id") Integer id){
        return wmMaterialService.deletePic(id);
    }

    //收藏图片
    @GetMapping("/collect/{id}")
    @ApiOperation("收藏图片")
    public ResponseResult collect(@PathVariable("id") Integer id){
        return wmMaterialService.isCollect(id,(short)1);
    }

    //取消收藏图片
    @GetMapping("/cancel_collect/{id}")
    @ApiOperation("取消收藏图片")
    public ResponseResult cancelCollect(@PathVariable("id") Integer id){
        return wmMaterialService.isCollect(id,(short)0);
    }
}
